// pages/repairOrderForm/billSelect.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    date: '2018-04-16',
    costTypeIndex:0,
    costType:1,
    costArray: [
      {
        id: '1',
        name: '修理费'
      },
      {
        id: '2',
        name: '加油费'
      },
      {
        id: '3',
        name: '其他费用'
      }
    ]
  },
   bindDateChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })
  },
  costTypeChnage:function(e){
    console.log('支出类型发送选择改变，携带值为', e.detail.value)
    var cType = this.data.costArray[e.detail.value].id;
    this.setData({
      costTypeIndex: e.detail.value,
      costType: cType
    })
  },
  formSubmit: function (e) {
    console.log('form发生了submit事件，携带数据为：', e.detail.value)
    const order = e.detail.value;
    order.price=0;
    order.weight=0;
    order.type=this.data.costType;
    order.adder =app.globalData.openId;
    wx.request({
      url: app.globalData.baseUrl+'order/addOrder', //仅为示例，并非真实的接口地址
      data: order,
      method: "POST",
      success: function (res) {
        if (res.data.code == 0) {
          wx.navigateBack({
            complete: function () {
              wx.showToast({
                title: "修改支出成功",
                icon: "success"
              });
            }
          });
        } else {
          wx.showToast({
            title: "修改支出失败",
            icon: "fail"
          })
        }
      }
    });
  },
  formReset: function () {
    console.log('form发生了reset事件')
  }
})